package com.afu.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: TestStrategyController
 * Package: com.afu.strategy
 * Description:
 *
 * @Author zxf
 * @Version 1.0
 */
@RestController
@RequestMapping("/testStrategyController")
public class TestStrategyController {
    @Autowired
    private ParkingTypeContext parkingTypeContext;

    @GetMapping("/testStratgy")
    public void testStrategy(@RequestParam("name") String name) {
        ParkingTypeEnum parkingTypeEnum = ParkingTypeEnum.getByName(name);
        if (parkingTypeEnum == null) {
            throw new RuntimeException("当前找不到 " + name + "的设置，请确认停车场系统名称！");
        }
        useStrategy(parkingTypeEnum);
    }

    private void useStrategy(ParkingTypeEnum parkingTypeEnum) {
        ParkingTypeStrategy parkingType = parkingTypeContext.getParkingType(parkingTypeEnum);
        parkingType.connet();
    }

}
